package com.bestcem.xm.ticket.enums;

import lombok.Getter;

/**
 * 账号来源枚举
 *
 * @author ympan <yuming.pan@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/27 11:47
 */
@Getter
public enum OrganizationSourceEnum {

    /**
     * 手动添加
     */
    ORGANIZATION_SOURCE_DEFAULT("ORGANIZATION_SOURCE_DEFAULT", 0),

    /**
     * 预约添加
     */
    ORGANIZATION_SOURCE_BOOKING("ORGANIZATION_SOURCE_BOOKING", 1),

    /**
     * 注册添加
     */
    ORGANIZATION_SOURCE_REGISTER("ORGANIZATION_SOURCE_REGISTER", 2),

    /**
     * 华为注册添加
     */
    ORGANIZATION_SOURCE_HUAWEIREGISTER("ORGANIZATION_SOURCE_HUAWEIREGISTER", 3),

    /**
     * 微信小程序注册添加
     */
    ORGANIZATION_SOURCE_WECHATREGISTTER("ORGANIZATION_SOURCE_WECHATREGISTTER", 4),

    /**
     * 微信公众号注册添加
     */
    ORGANIZATION_SOURCE_WECHATOFFIREGISTER("ORGANIZATION_SOURCE_WECHATOFFIREGISTER", 5),

    /**
     * 开放平台接入
     */
    ORGANIZATION_SOURCE_OPENPLATFORM("ORGANIZATION_SOURCE_OPENPLATFORM", 6);

    private final String name;

    private final Integer index;

    OrganizationSourceEnum(String name, Integer index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 根据 index 获取枚举实体
     * 找不到则返回 null
     *
     * @param index 账号来源index
     * @return 账号来源枚举
     * @author <yuming.pan@idiaoyan.com>
     * @date 11:49 2021/8/27
     */
    public static OrganizationSourceEnum getByIndex(Integer index) {
        for (OrganizationSourceEnum value : values()) {
            if (value.getIndex().equals(index)) {
                return value;
            }
        }
        return null;
    }
}
